package com.onlyphoto.onlymall.mvp.presenter

import android.content.Context
import com.onlyphoto.onlymall.base.BaseNetworkResponse
import com.onlyphoto.onlymall.base.BaseObserver

import com.onlyphoto.onlymall.mvp.contract.CCategory
import com.onlyphoto.onlymall.mvp.model.MCategoryImpl
import com.onlyphoto.onlymall.base.BasePresenter
import com.onlyphoto.onlymall.bean.response.CategoryBean
import com.onlyphoto.onlymall.bean.response.SingleActivityBean


class PCategoryImpl(mContext: Context, mView: CCategory.IVCategory) : BasePresenter<CCategory.IVCategory, MCategoryImpl>(mContext, mView, MCategoryImpl()), CCategory.IPCategory {

    override fun getCategory(grade: Int, up_id: String) {
        mModel.requestCategory(grade, up_id, object : BaseObserver<ArrayList<CategoryBean>>(mContext.get()){
            override fun onSuccess(data: ArrayList<CategoryBean>?, msg: String?) {
                if (up_id == ""){
                    mView.getCategorySuccess(data!!)
                } else {
                    mView.getSecondarySuccess(data!!)
                }
            }

            override fun onCodeError(t: BaseNetworkResponse<ArrayList<CategoryBean>>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }
        })
    }

    override fun requestActivitySingle(use_range: Int, range_cat1_id: Int) {
        mModel.requestSingleActivity(use_range, range_cat1_id, object : BaseObserver<SingleActivityBean>(mContext.get()){
            override fun onSuccess(data: SingleActivityBean?, msg: String?) {
                mView.requestActivitySingleSuccess(data!!)
            }

            override fun onCodeError(t: BaseNetworkResponse<SingleActivityBean>?) {
            }

            override fun onFailure(e: Throwable?) {
            }

            override fun onRequestStart() {
            }

            override fun onFinally() {
            }

        })
    }
}
